﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SPMS.Log.Core;

namespace SPMS.Log.Repository
{
    /// <summary>
    /// 日志存储器接口
    /// </summary>
    /// <remarks>提供了日志记录器的管理功能</remarks>
    /// <history>
    /// [zanezeng]               2009/10/13 12:11    创建
    /// </history>
    public interface ILoggingRepository : IDisposable
    {
        #region ---Property

        /// <summary>
        /// 获得或者设置日志存储器的名称
        /// </summary>
        /// <value>日志存储器的名称</value>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]               2009/10/15 10:49    创建
        /// </history>
        string Name
        {
            get;
        }

        /// <summary>
        /// 获得或者设置默认的日志级别
        /// </summary>
        /// <value>默认的日志级别</value>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]               2009/10/15 11:43    创建
        /// </history>
        Level DefaultLevel
        {
            get;
        }

        /// <summary>
        /// 获得当前存储器中注册的所有日志追加器
        /// </summary>
        /// <value>当前存储器中存储的所有日志追加器</value>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]               2009/10/13 13:51    创建
        /// </history>
        ILogAppender[] Appenders
        {
            get;
        }

        /// <summary>
        /// 获得当前存储器中注册的所有日志记录器
        /// </summary>
        /// <value>当前存储器中注册的所有日志记录器</value>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]               2009/10/13 13:52    创建
        /// </history>
        ILogger[] Loggers
        {
            get;
        }

        /// <summary>
        /// 获得默认的日志记录器
        /// </summary>
        /// <value>默认的日志记录器</value>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]               2009/10/13 13:57    创建
        /// </history>
        ILogger DefaultLogger
        {
            get;
        }

        /// <summary>
        /// 获得日志级别映射表
        /// </summary>
        /// <value>日志级别映射表</value>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]               2009/10/16 15:40    创建
        /// </history>
        LevelMap LevelMap
        {
            get;
        }

        /// <summary>
        /// 获得一个值，该值用于判断当前日志存储器是否已经关闭
        /// </summary>
        /// <value>
        /// 	如果日志存储器已经关闭，则返回<c>true</c>，否则返回<c>false</c>。
        /// </value>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]               2010/1/6 11:02    创建
        /// </history>
        bool IsClosed
        {
            get;
        }

        #endregion

        #region ---Method

        /// <summary>
        /// 判断给定名称的日志记录器是否存在
        /// </summary>
        /// <param name="name">要判定的日志记录器的名称</param>
        /// <returns>
        /// 	<c>true</c>：给定名称的日志记录器存在<br/>
        /// 	<c>false</c>：给定名称的日志记录器不存在
        /// </returns>
        /// <exception cref="ObjectDisposedException">当前日志存储器已经被关闭</exception>
        /// <exception cref="ArgumentNullException"><paramref name="name"/>为<c>null</c>引用或者为空字符串。</exception>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]               2009/10/13 13:58    创建
        /// </history>
        bool Exists(string name);

        /// <summary>
        /// 获得给定名称的日志记录器
        /// </summary>
        /// <param name="name">要获得的日志记录器的名称</param>
        /// <returns>给定名称的日志记录器，如果给定名称的日志记录器不存在，则尝试返回上一级名称的日志记录器，如果根名称的日志记录器也不存在，则返回默认的日志记录器</returns>
        /// <remarks></remarks>
        /// <exception cref="ObjectDisposedException">当前日志存储器已经被关闭</exception>
        /// <exception cref="ArgumentNullException"><paramref name="name"/>为<c>null</c>引用或者为空字符串。</exception>
        /// <history>
        /// [zanezeng]               2009/10/13 13:56    创建
        /// </history>
        ILogger GetLogger(string name);

        /// <summary>
        /// 获得给定名称的日志追加器
        /// </summary>
        /// <param name="name">要获得的日志追加器的名称</param>
        /// <returns>给定名称的日志追加器，如果给定名称的日志追加器不存在，则返回<c>Null</c></returns>
        /// <remarks></remarks>
        /// <exception cref="ObjectDisposedException">当前日志存储器已经被关闭</exception>
        /// <exception cref="ArgumentNullException"><paramref name="name"/>为<c>null</c>引用或者为空字符串。</exception>
        /// <history>
        /// [zanezeng]               2009/10/13 14:00    创建
        /// </history>
        ILogAppender GetAppender(string name);

        /// <summary>
        /// 将给定的日志条目写入到日志记录器中
        /// </summary>
        /// <param name="entry">要写入的日志条目</param>
        /// <remarks></remarks>
        /// <exception cref="ObjectDisposedException">当前日志存储器已经被关闭</exception>
        /// <history>
        /// [zanezeng]               2009/10/14 11:55    创建
        /// </history>
        void WriteLog(LogEntry entry);

        /// <summary>
        /// 获得一个值，该值用于判断给定名称的日志记录器是否允许输出给定级别的日志
        /// </summary>
        /// <param name="name">日志记录器的名称</param>
        /// <param name="level">要判定的日志级别</param>
        /// <returns>
        /// 	<c>true</c>：允许输出<br/>
        /// 	<c>false</c>：不允许输出
        /// </returns>
        /// <remarks></remarks>
        /// <exception cref="ArgumentNullException"><paramref name="name"/>为<c>null</c>引用或者为空字符串。</exception>
        /// <history>
        /// [zanezeng]               2009/10/14 12:07    创建
        /// </history>
        bool IsLevelEnabled(string name, Level level);

        /// <summary>
        /// 关闭当前日志存储器
        /// </summary>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]               2010/1/6 11:03    创建
        /// </history>
        void Close();

        #endregion

        #region ---Event

        /// <summary>
        /// 配置重置事件
        /// </summary>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]               2009/10/16 10:38    创建
        /// </history>
        event EventHandler ConfigurationReset;

        /// <summary>
        /// 配置发生变化事件
        /// </summary>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]               2009/10/16 10:38    创建
        /// </history>
        event EventHandler ConfigurationChanged;

        /// <summary>
        /// 日志存储器被关闭事件
        /// </summary>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]               2010/1/6 11:04    创建
        /// </history>
        event EventHandler Closed;

        #endregion
    }
}
